<?php
if(!defined('FROM_INDEX'))exit('Invalid request');

require_once ROOT_PATH.'service/base.service.php';
require_once ROOT_PATH.'include/sql/function/feed.sql.php';

class FeedService extends  BaseService
{
	private $sqlFunc;
	
	function __construct()
	{
		parent::__construct();
		
		$this->sqlFunc = new FeedSqlFunc();
	}
	
	/**
	 * 
	 * 根据uid获取动态信息
	 * @param array $requesst
	 */
	function get_feed_count($uid)
	{
		$result = $this->sqlFunc->get_feed_count($uid);
		
		$list = array();
		$list['at_count'] = $list['follow_count'] = $list['like_count'] = $list['comment_count'] = 0;
		
		if (check_array($result))
		{
			foreach ($result as $arr)
			{
				switch ($arr['type'])
				{
					case 'a':
						$list['at_count']++;
						break;
					case 'f':
						$list['follow_count']++;
						break;
					case 'l':
						$list['like_count']++;
						break;
					case 'c':
						$list['comment_count']++;
						break;
					default:
						break;
				}
			}
		}
		
		return $list;
	}
	
	/**
	 * 
	 * 根据uid获取动态信息
	 * @param array $requesst
	 */
	function get_list_by_uid($request)
	{
		return $this->sqlFunc->get_list_by_uid($request);
	}
	
	/**
	 * 
	 * 根据uid获取动态信息
	 * @param array $requesst
	 */
	function get_follow_list_by_uid($request)
	{
		return $this->sqlFunc->get_follow_list_by_uid($request);
	}
	
	/**
	 * 
	 * 根据ID获取动态信息
	 * @param array $request
	 */
	function get($request)
	{
		return $this->sqlFunc->get($request['id']);
	}
	
	/**
	 * 
	 * 新增动态
	 * @param array $request
	 */
	function add($request)
	{
		return $this->sqlFunc->add($request);
	}
	
	/**
	 * 
	 * 更新动态
	 * @param array $request
	 */
	function update($request)
	{
		return $this->sqlFunc->update($request);
	}
	
	/**
	 * 
	 * 删除动态
	 * @param array $request
	 */
	function delete($request)
	{
		return $this->sqlFunc->delete($request);
	}
}